package com.wwg.util.date;

import org.apache.log4j.Logger;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期处理单元
 */
public class DateUtil {

    static Logger logger = Logger.getLogger(DateUtil.class);


    public static final String FORMAT_YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss SSS";
    public static final String FORMATE_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String FORMATE_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    public static final String FORMATE_YYYY_MM_DD = "yyyy-MM-dd";
    public static final String FORMATE_YYYYMMDD = "yyyyMMdd";
    public static final String FORMATE_YYYY__MM__DD = "yyyy/MM/dd";
    public static final String FORMATE_YYYY__MM__DD_HH_MM_SS = "yyyy/MM/dd HH:mm:ss";
    public static final String FORMATE_YYYY__MM__DD_HH_MM = "yyyy/MM/dd HH:mm";
    public static final String FORMATE_HHMMSS = "HHmmss";
    public static final String DATE_FORMAT_YYYYMMDDHHMMSSNNN = "yyyyMMddHHmmssnnn";
    public static final String FORMATE_YYMMDD = "yyMMdd";
    public static final String FORMATE_YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss SSS";
    public static final String FORMATE_YYYY_MMDD = "yyyy-MMdd";
    public static final String DATE_FORMAT_YYYYMMDDHHMMSSSSS = "yyyyMMddHHmmssSSS";
    public static final String FORMATE_HHMMSSSSS = "HHmmssSSS";
    public static final String FORMATE_YYYY = "yyyy";
    public static final String FORMATE_MMDD = "MMdd";
    public static final String FORMATE_YYYY_MM_DD_CN = "yyyy年MM月dd日";
    public static final String FORMATE_YYYY_MM_CN = "yyyy年MM月";

    public static final String DATA_FORMAT = "yyyyMMddHHmmss";
    public static final String DAY_FORMAT = "MM-dd";
    public static final String FULL_ST_FORMAT = "yyyy-MM-dd HH:mm";

    private DateUtil() {
        throw new IllegalStateException("Utility class");
    }


    /**
     * @Method: strToDatestr @Description: yyyyMMddHHmmss转yyyy-MM-dd
     * HH-mm @param @param date @param @return @return
     * String @throws
     */
    public static String strToDatestr(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat(DATA_FORMAT);
        SimpleDateFormat sdf2 = new SimpleDateFormat(FULL_ST_FORMAT);
        String result = null;
        try {
            result = sdf2.format(sdf.parse(date));
        } catch (ParseException e) {
            logger.error("DateUtil日期转换时参数异常：=>", e);
        }
        return result;
    }


    public static String dateTimeToString(Date dateTime) {
        SimpleDateFormat format = new SimpleDateFormat(DAY_FORMAT);
        String dt = format.format(dateTime);
        return dt;
    }

    /**
     * 获取当前日期
     * @param format
     * @return
     */
    public static String getCurrentDate(String format) {
        return new SimpleDateFormat(format).format(new Date());
    }

}
	
